'''
Created on 17/03/2014

@author: dingliangl
'''






class SurroundingGameEasy:
    def isDom(self, x, y, s):
        if s[y][x]:
            return True
        if x > 0 and not s[y][x-1]:
            return False
        if x < len(s[0]) - 1 and not s[y][x+1]:
            return False
        if y > 0 and not s[y-1][x]:
            return False
        if y < len(s) - 1 and not s[y+1][x]:
            return False
        return True
    
    def score(self, cost, benefit, stone):
        c = []
        for cs in cost:
            ln = []
            for ch in list(cs):
                ln.append(int(ch))
            c.append(ln)
        b = []
        for bs in benefit:
            ln = []
            for ch in list(bs):
                ln.append(int(ch))
            b.append(ln)
        s = []
        for ss in stone:
            ln = []
            for ch in list(ss):
                ln.append(ch=='o')
            s.append(ln)
        
        score = 0
        print len(s)
        for y in range(len(s)):
            for x in range(len(s[0])):
                print y, x
                if self.isDom(x, y, s):
                    score += b[y][x]
                if s[y][x]:
                    score -= c[y][x]
        return score



s = SurroundingGameEasy()

cost = ["4362","4321"]
benefit = ["5329","5489"]
stone = ["...o","..o."]

#print s.score(cost, benefit, stone)


class Stamp:
    def paint_seg(self, seg, l):
        lseg = list(seg)
        r = 0
        while lseg != []:
            while lseg != [] and lseg[0] == '*':
                lseg.pop(0)
            while lseg != [] and lseg[0] != '*':
                r += 1
                if len(lseg) >= l:
                    lseg = lseg[l:]
                else:
                    lseg = []
        return r
        
    
    def paint(self, board, stampCost, pushCost):
        smaxl = min(map(len, board))
        r = []
        for l in range(1, smaxl+1):
            t = 0
            for seg in board:
                t += self.paint_seg(seg, l)
            if t == 0:
                r.append(0)
                break
            r.append(stampCost * l + pushCost * t)
        return min(r)
    
    def gen_paint_meth(self, dcolor, colorord):
        cl = list(dcolor)
        first = []
        second = []
        third = []
        for ch in cl:
#             if ch == colorord[0] or ch == '*':
#                 first.append('1')
#             else:
#                 first.append('*')
            if ch == colorord[0] or ch == '*':
                first.append('1')
            else:
                first.append('*')
            
            if ch == colorord[0]:
                second.append(' ')  
            elif ch == colorord[1]:
                second.append('1')
            elif ch == colorord[2] or ch == '*':
                second.append('*')
            
            if ch == colorord[0] or ch == colorord[1]:
                third.append(' ')
            elif ch == [2]:
                third.append('1')
            else:
                third.append('*')
        #bs = [first, second, third]
        r = map(lambda x:filter(lambda y:y!='',(''.join(x)).split(' ')), [first, second, third])
        #print r
        return r
    
    def getMinimumCost(self, desiredColor, stampCost, pushCost):
        allcolorord = ['RGB', 'RBG', 'GRB', 'GBR', 'BRG', 'BGR']
        r = []
        for co in allcolorord:
            s = self.gen_paint_meth(desiredColor, co)
            sub = 0
            for ss in s:
                sub += self.paint(ss, stampCost, pushCost)
            r.append(sub)
        print r
        return 0


s = Stamp()

desiredColor = '*R*RG*G*GR*RGG*G*GGR***RR*GG'
stampCost = 7
pushCost = 1

print s.getMinimumCost(desiredColor, stampCost, pushCost)
#print s.paint_seg('1**1*1', 3)
#[f,s,t] = s.gen_paint_meth(list("*R*RG*G*GR*RGG*G*GGR***RR*GG"), 'RGB')
# print f,s,t
# print filter(lambda x:x!='',s.split(' '))
# print f.split(' ')

